home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13385 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  66 lines

  1. Newsgroups: comp.lang.c++,comp.lang.java
  2. Path: uu4news.netcom.com!friend!news
  3. From: rich@kastle.com (Richard Krehbiel)
  4. Subject: Re: Java: What's the Big Deal?
  5. Message-ID: <1996Mar25.131115.29988@friend.kastle.com>
  6. Sender: news@friend.kastle.com (News)
  7. Reply-To: rich@kastle.com
  8. Organization: Kastle Development Associates
  9. X-Newsreader: Forte Free Agent 1.0.82
  10. References: <milodDoF9JF.K32@netcom.com> <1996Mar20.154600.12011@amc.com> <4iuenj$ng2@decaxp.HARVARD.EDU> <4iuo1r$e46@kai.com>
  11. Date: Mon, 25 Mar 1996 13:09:52 GMT
  12.  
  13. robison@kai.com (Arch Robison) wrote:
  14.  
  15. >Some people wrote:
  16. >>
  17. >>: : >>2) No header files => faster compilation
  18. >>: : 
  19. >>: : >Nonsense. Header files are simply text that gets included where you want it. If 
  20. >>: : >you write the same code without header files it will not magically compile 
  21. >>: : >faster.
  22.  
  23. Well... It may, and you may or may not notice the difference.  Each
  24. #include causes the OS to perform a file system operation to locate
  25. the header file.  If you in-line all the header files these lookups
  26. are not done.
  27.  
  28. Usually the trick for omitting inclusion of a file that's already
  29. included is to put:
  30.  
  31. #ifndef HEADER_H
  32. #define HEADER_H
  33. /* text of header.h */
  34. #endif
  35.  
  36. ...inside the header file, and I consider this the best way because it
  37. conveniently centralizes the management and reduces the possibility of
  38. errors in programs that include this header.  However, a performance
  39. enhancement I used on my old floppy-disk-based Amiga compiler setup
  40. was this instead:
  41.  
  42. #ifndef HEADER_H
  43. #define HEADER_H
  44. #include "header.h"
  45. #endif
  46.  
  47. The speedup is because now there is no need for the compiler to open
  48. header.h and read all of it's contents to find that it has been
  49. totally conditionalized away.  On track-buffered floppy disks this was
  50. so much faster as to be worth the effort to remember to type the
  51. incant for each inlcusion (and retype and recompile for each time I
  52. forgot it/botched it).
  53.  
  54. >If header files don't slow down compilation, why do so many C/C++
  55. >compilers offer a "precompiled header" feature to make compilation faster?
  56.  
  57. It's not because headers in particular are slow, but because
  58. *compiling* is slow, when compared with *not* compiling.  "make" and
  59. Makefiles serve the same purpose, trying not to compile when it can be
  60. known it's not necessary.
  61.  
  62. --
  63. Richard Krehbiel, Kastle Systems, Arlington VA USA
  64. rich@kastle.com (work) or richk@mnsinc.com (personal)
  65.  
  66.